<?php

namespace app\model;

//use support\Model;
use app\controller\wmapi\IndexController;
use support\Db;
use Illuminate\Database\Eloquent\Model;

class WaAccountingInformationOperateLog
{
//accountinginformation
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_order_account_information_operate_log';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;


    /**
     * 出账单列表
     * @param $page
     * @param $pageNum
     * @param string[] $fields
     * @param array $condition
     */
    public static function list($page, $pageNum, $fields = ['*'], $condition = [], $between = [])
    {
        $condition [] = ['is_show','=',1];
        $offset = ($page - 1) * $pageNum;
        if ($between) {
            $model = Db::table('wa_order_account_information_operate_log')
                ->select($fields)
                ->where($condition)
                ->whereBetween('created_at', $between);
        } else {
            $model = Db::table('wa_order_account_information_operate_log')
                ->select($fields)
                ->where($condition);
        }


        $count = $model->count();
        $list = $model
            ->orderBy('id', 'desc')
            ->offset($offset)
            ->limit($pageNum)
            ->get();


        return json_encode(['list' => $list, 'count' => $count]);


    }


    /**
     * @param $page
     * @param $pageNum
     * @param string[] $fields
     * @param array $condition
     */
    public static function all($fields, $condition)
    {

        $list = Db::table('wa_order_account_information_operate_log')
                ->select($fields)
                ->where($condition)
                ->get();

        return json_encode($list);


    }


    /**
     * 某笔账单的详情及其明细
     * @param $condition
     * @return false|string
     */
    public static function find($condition)
    {
        $res = Db::table('wa_order_account_information_operate_log')
            ->select('*')
            ->where($condition)
            ->first();
        return json_encode($res);
    }

    public static function created($data)
    {
        return Db::table('wa_order_account_information_operate_log')->insertGetId($data);
    }

    public static function updated($data, $where)
    {
        $result = Db::table('wa_order_account_information_operate_log')->where($where)->update($data);
        return $result;
    }





}